package com.sl.springmvc.swagger.dao;

import com.sl.springmvc.swagger.bean.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserDaoImpl extends BaseDaoImpl implements UserDao {

    @Override
    public List<User> findAll() {
        String sql = "select id, user_name, head_portrait_id from user";
        return this.getLocalMysqlJdbcTemplate().query(sql, new BeanPropertyRowMapper<User>(User.class));
    }

    @Override
    public User findUserByName(String userName) {
        String sql = "select id, user_name, head_portrait_id from user where user_name=:userName";
        Map<String, String> params = new HashMap<String, String>();
        params.put("userName", userName);
        List<User> userList =  this.getLocalMysqlJdbcTemplate().query(sql, params, new BeanPropertyRowMapper<User>(User.class));
        if(userList.size() >0){
            return userList.get(0);
        }
        return null;
    }
}
